package top.hcode.hoj.service.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nutz.lang.Strings;
import org.springframework.stereotype.Component;
import top.hcode.hoj.dao.CollCreatedWorksScoreDao;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.coll.CollCreatedWorksScore;

/**
 * @author orangej
 * @since 2025-01-26
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AdminCollCreatedWorksScoreService {
    private final CollCreatedWorksScoreDao collCreatedWorksScoreDao;

    public IPage<CollCreatedWorksScore> getCollCreatedWorksScoreList(QuerySampleDTO querySampleDTO) {
        IPage<CollCreatedWorksScore> pager = new Page<>(querySampleDTO.getCurrentPage(), querySampleDTO.getLimit());

        QueryWrapper<CollCreatedWorksScore> query = new QueryWrapper<>();
        if (Strings.isNotBlank(querySampleDTO.getKeyword())) {
            query.like("title", querySampleDTO.getKeyword());
        }
        collCreatedWorksScoreDao.page(pager, query);
        return pager;
    }

    public CollCreatedWorksScore getCollCreatedWorksScore(Long id) {
        return collCreatedWorksScoreDao.getById(id);
    }

    public CollCreatedWorksScore saveCollCreatedWorksScore(CollCreatedWorksScore collCreatedWorksScore) {
        collCreatedWorksScoreDao.saveOrUpdate(collCreatedWorksScore);
        return collCreatedWorksScore;
    }

    public void deleteCollCreatedWorksScore(Long id) {
        collCreatedWorksScoreDao.removeById(id);
    }
}
